package com.tz.fruit.entity;


import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.tz.fruit.util.CustomDateSerializer;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

import javax.persistence.*;

/**
 * 顾客评论实体类
 */
@Entity
@Table(name="FRUIT_COMMENT")
public class Comment implements Serializable{
	private Long commentId;//评论ID

	private String username;//用户名

	private int rank;//评分等级 1满意 2一般 3差评
	private String content;//内容

	private Date commentDate;//评论日期
	private int isReply ;//标志  该评论是否已经有回复 0：未回复  1：已回复
	
	private Product product;//所属商品

	private List<Image> images;

	@OneToMany(mappedBy = "comment",cascade = CascadeType.ALL,fetch = FetchType.EAGER)
	public List<Image> getImages() {
		return images;
	}

	public void setImages(List<Image> images) {
		this.images = images;
	}

	public Comment() {
	}

	public Comment(String username, int rank, String content, Date commentDate, int isReply, Product product) {
		super();
		this.username = username;
		this.rank = rank;
		this.content = content;
		this.commentDate = commentDate;
		this.isReply = isReply;
		this.product = product;
	}

	@Id
	@GeneratedValue
	public Long getCommentId() {
		return commentId;
	}

	public void setCommentId(Long commentId) {
		this.commentId = commentId;
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public int getRank() {
		return rank;
	}

	public void setRank(int rank) {
		this.rank = rank;
	}

	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}

	@JsonSerialize(using = CustomDateSerializer.class)
	@Temporal(TemporalType.TIMESTAMP)
	public Date getCommentDate() {
		return commentDate;
	}

	public void setCommentDate(Date commentDate) {
		this.commentDate = commentDate;
	}
	

	public int getIsReply() {
		return isReply;
	}

	public void setIsReply(int isReply) {
		this.isReply = isReply;
	}

	@ManyToOne
	@JoinColumn(name="pid")
	public Product getProduct() {
		return product;
	}

	public void setProduct(Product product) {
		this.product = product;
	}


	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((commentId == null) ? 0 : commentId.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Comment other = (Comment) obj;
		if (commentId == null) {
			if (other.commentId != null)
				return false;
		} else if (!commentId.equals(other.commentId))
			return false;
		return true;
	}

	@Override
	public String toString() {
		return "Comment [commentId=" + commentId + ", username=" + username + ", rank=" + rank + ", content=" + content
				+ ", commentDate=" + commentDate + ", isReply=" + isReply + "]";
	}

}
